﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HWR_Ants.Classes;

namespace HWR_Ants.Forms
{
    public partial class fTSP_Painting : Form
    {
        private TSP_File tspFileToPaint;

        internal TSP_File TspFileToPaint
        {
            get { return tspFileToPaint; }
            set { tspFileToPaint = value; }
        }

        public fTSP_Painting()
        {
            InitializeComponent();
            this.WindowState = FormWindowState.Maximized;
        }
    
        private void fTSP_Painting_Paint(object sender, PaintEventArgs e)
        {
            if (tspFileToPaint == null)
                return;

            Image drawImage = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            Graphics g = Graphics.FromImage(drawImage);
            
            // TODO: Take it or not???
            g.ScaleTransform(0.5f, 0.5f);

            foreach(Point p in tspFileToPaint.Coordinates.Values)
            {
                g.DrawEllipse(Pens.Black, p.X + 10, p.Y + 10, 5,5); 
            }
            pictureBox1.Image = drawImage;
        }

        private void startenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            WorldBuilder wb = new WorldBuilder();

            IList<Point> p = tspFileToPaint.Coordinates.Values;
            wb.AddCities(p);
            for (int i = 0; i < p.Count - 1; i++)
            {
                for (int j = i + 1; j < p.Count; j++)
                {
                    wb.AddRoad(p[i], p[j]);
                }
            }
            RoadMap rm = new RoadMap(wb);
            rm.UpdateEvent += new RoadMap.UpdateEventHandler(updateGraphic);
            IEnumerable<City> temp = rm.FindTour();
        }

        void updateGraphic(RoadMap sender, UpdateEventArgs e)
        {
            MessageBox.Show(e.ToString());
        }

        private void fTSP_Painting_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
                contextMenuStrip1.Show();
        }

        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            fTSP_Painting_MouseClick(sender, e);
        }
    }
}
